package com.chaowen.yixin;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.chaowen.xuefeng.Fragment_index;
import com.chaowen.xuefeng.OAFragment;

public class LeftSlidingMenuFragment extends Fragment implements
		OnClickListener {
	private View oa_index; // 首页
	private View yixinBtnLayout; // 左侧菜单的易信功能
	private View circleBtnLayout; // 左侧菜单的朋友圈功能
	private View settingBtnLayout; // 左侧菜单的设置功能

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.main_left_fragment, container,
				false);
		oa_index = view.findViewById(R.id.oa_index_BtnLayout);
		oa_index.setOnClickListener(this);
		yixinBtnLayout = view.findViewById(R.id.yixinBtnLayout);
		yixinBtnLayout.setOnClickListener(this);
		circleBtnLayout = view.findViewById(R.id.circleBtnLayout);
		circleBtnLayout.setOnClickListener(this);
		settingBtnLayout = view.findViewById(R.id.settingBtnLayout);
		settingBtnLayout.setOnClickListener(this);

		System.out.println();
		return view;
	}

	@Override
	public void onClick(View v) {
		OAFragment newContent = null;
		switch (v.getId()) {
		case R.id.oa_index_BtnLayout: // 首页的点击事件
			newContent = new Fragment_index();
			
			oa_index.setSelected(true);
			yixinBtnLayout.setSelected(false);
			circleBtnLayout.setSelected(false);
			settingBtnLayout.setSelected(false);

			break;
		case R.id.yixinBtnLayout: // 易信的点击事件
			newContent = new Fragment_yixin();
			oa_index.setSelected(false);
			yixinBtnLayout.setSelected(true);
			circleBtnLayout.setSelected(false);
			settingBtnLayout.setSelected(false);

			break;
		case R.id.circleBtnLayout: // 朋友圈的点击事件
			newContent = new Fragment_friend();
			oa_index.setSelected(false);
			yixinBtnLayout.setSelected(false);
			circleBtnLayout.setSelected(true);
			settingBtnLayout.setSelected(false);
			break;
		case R.id.settingBtnLayout: // 设置的点击事件
			newContent = new Fragment_setting();
			oa_index.setSelected(false);
			yixinBtnLayout.setSelected(false);
			circleBtnLayout.setSelected(false);
			settingBtnLayout.setSelected(true);
			break;
		default:
			break;
		}

		if (newContent != null)
			switchFragment(newContent);

	}

	/*
	 * 切换到不同的功能内容
	 */
	private void switchFragment(OAFragment fragment) {
		if (getActivity() == null)
			return;
		MainActivity ra = (MainActivity) getActivity();
		ra.switchContent(fragment);

	}
}
